/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package mysql.process;

/**
 *
 * @author dell
 */
import entity.function.Process;
import entity.function.Requset;
import entity.function.Result;
public abstract class Processor 
{
//columns_______________________________________________________________________    
private Process buffer;   
private Thread thread;
private String name;
//functions_____________________________________________________________________
     //constructor______________________________________________________________
public Processor()
{
     
}
public Processor(String name)
{
     this.name=name;
}
     //getter___________________________________________________________________
public String getName()
{
     return name;
}
     //setter___________________________________________________________________
     // operator________________________________________________________________
protected abstract Result handle(Requset r);//thread run this method
protected void work()
{
     Object o=buffer.Pop();
     Requset requset= (Requset)o;
     Result result=handle(requset);
}
protected boolean init()
{
     boolean result=false;
     buffer=new Process("entity.function.Requset");
     thread=new Thread(new Runnable()
     {
         @Override
         public void run() 
         {
             while(true)
             {
                  Processor.this.work();
             }
         }
     });
     result=true;
     return result;
}
public void process()
{
     if(this.init()) thread.start();;
}
public void add(Requset r)
{
     this.buffer.insert(r);
}
}
